<script>
	export default {
		onLaunch: function() {
			 this.getUser()
			// uni.setStorageSync('user', {
			// 	"UserID": 3,
			// 	"OpenID": "oF0KA6dP5OuOZSsnpKgh4Hxzlbo0",
			// 	"UserName": "钒钒",
			// 	"HeaderUrl": "https://thirdwx.qlogo.cn/mmopen/vi_32/D2XevEHZeaictpcR1Gacewtr2g5nRgSnKB821aR5vDKooFGOIVs6GJLU9qFibibeWibdd3KibpskswhdrocIPubpNwA/132",
			// 	"IsRenZheng": true,
			// 	"ZhanShangInfo": {
			// 		"ZhangShangID": 289,
			// 		"ZhangShangName": "测试商家",
			// 		"Content": null,
			// 		"ZhangShangLoge": "@/upload/images/2023/5/t_a8e7b352dde86a8a.jpg",
			// 		"ZhangShangSeat": "E12",
			// 		"ImageUrl": null
			// 	}
			// })
		},
		onShow: function() {

		},
		onHide: function() {

		},
		methods: {
			async getUser() {
				// let openid = uni.getStorageSync('openid')
				// if (!openid) {
				let code = await this.$api.getCode()
				let res = await this.$api.getOpenId({
					code
				})
				uni.setStorageSync('openid', res.UserData.openid)
				uni.setStorageSync('access_token', res.UserData.access_token)
				let isResgist = await this.$api.isRegist({
					openid: res.UserData.openid
				})
				if (isResgist.UserData) {
					// 一注册
					uni.setStorageSync('user', isResgist.UserData)
				} else {
					// 未注册
					let user = await this.$api.getUserInfo({
						openid: res.UserData.openid,
						accessToken: res.UserData.access_token
					})
					await this.$api.regist({
						OpenId: res.UserData.openid,
						HeadUrl: user.UserData.headimgurl,
						UserName: user.UserData.nickname
					})
					let userInfo = await this.$api.isRegist({
						openid: res.UserData.openid
					})
					uni.setStorageSync('user', userInfo.UserData)

				}
			}

			// }
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
	@import "common/demo.scss";

	.u-row {
		width: 100% !important;
	}

	.uni-flex {
		display: flex;
	}
</style>